/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package client;
import entreprise.Reservation;
import entreprise.ReservationService;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author duonghau
 */

public class ReservationBean{
    private String reservationID;
    private String patientName;
    private String patientPhoneNumber;
    private String patientEmail;
    private Date reservationTime;
    private String require;
    private String message;
    private String styleMessage="infor";
    public String getReservationID() {
        return reservationID;
    }

    public void setReservationID(String reservationID) {
        this.reservationID = reservationID;
    }

    public String getPatientName() {
        return patientName;
    }

    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }

    public String getPatientPhoneNumber() {
        return patientPhoneNumber;
    }

    public void setPatientPhoneNumber(String patientPhoneNumber) {
        this.patientPhoneNumber = patientPhoneNumber;
    }

    public String getPatientEmail() {
        return patientEmail;
    }

    public void setPatientEmail(String patientEmail) {
        this.patientEmail = patientEmail;
    }

    public Date getReservationTime() {
        return reservationTime;
    }

    public void setReservationTime(Date reservationTime) {
        this.reservationTime = reservationTime;
    }

    public String getRequire() {
        return require;
    }

    public void setRequire(String require) {
        this.require = require;
    }

    public String getMessage() {
        return message;
    }

    public String getStyleMessage() {
        return styleMessage;
    }    
    
    
    public ArrayList<Reservation> getReservations(){
        ReservationService reservationService=new ReservationService();
        ArrayList<Reservation> reservations=reservationService.reservations();
        return reservations;        
    }
    
    public void getReservationDetail(){
        if(reservationID!=null){
            ReservationService reservationService=new ReservationService();
            Reservation reservation = reservationService.getReservation(reservationID);
            if(reservation!=null){
                patientName=reservation.getPatientName();
                patientPhoneNumber=reservation.getPatientPhoneNumber();
                patientEmail=reservation.getPatientEmail();
                reservationTime=reservation.getReservationTime();
                require=reservation.getRequire();
            }
        }        
    }
    public String addReservation(){
        String emailContent="Thank you for choosing e-clinic, Below you can find your confirmation. If any of the informations incorrect, please contact our.<br/>" +
                "<h2>Reservation informartion:</h2>"+
                "<b>Name:</b>" +patientName+"<br/>"+
                "<b>Date:</b>" +String.valueOf(reservationTime)+"<br/>"+
                "<b>Require:</b>"+require;        
        ReservationService reservationService=new ReservationService();
        if(reservationService.createReservation("", patientName, patientPhoneNumber, patientEmail, reservationTime, require)){
            message="Reservation successful.";
            MailInform mailInform=new MailInform();
            if(mailInform.sendMail("duonghau.emarketing@gmail.com", patientEmail, "Inform reservation", emailContent)){
                message+="A email has been sent to user";
            }else{
                message+="Failed to send email to user";
            }               
            styleMessage="success";
            return "index";
        }else{
            message="Unsuccess";
            styleMessage="error";
            return "index";
            
        }        
    }
    public String editReservation(){
        ReservationService reservationService=new ReservationService();
        if(reservationService.updateReservation(reservationID, patientName, patientPhoneNumber, patientEmail, reservationTime, require)){
            return "reservations";
        }else{
            return "error";
        } 
    }
    public String deleteReservation(String reservationID){
        ReservationService reservationService=new ReservationService();
        if(reservationService.deleteReservation(reservationID)){
            return "reservations";
        }else{
            return "error";
        }
    }    
}
